<?php
include_once '../quizzes/Business/survey_result_service.php';
include_once '../quizzes/Business/survey_answer_user_service.php';
$question_id =explode(",", $_POST["survey_question"]);
$mark = 0;
$result ='';
$is_no_choise = false;
$qa_ids=array();
foreach( $question_id as $id)
{
	if(!isset($_POST[$id])){
		$is_no_choise =  true;
	}else{
		$qa_id=0;
		$qa_mark =0;
		list($qa_id,$qa_mark) = explode(";", $_POST[$id]);
		$mark =  $mark + $qa_mark;
		$qa_ids[]= $qa_id;

	}
}
if($is_no_choise){
	include_once 'quiz.php';
}else{
	$content=$content.'<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>';
	$user_id=$_POST["user_id"];
	foreach( $qa_ids as $id)
	{
		$t = time();
		survey_answer_user_service::insert_survey_answer_user(new survey_answer_user(0,$id,$user_id,date("Y-m-d", $t)));
	}
	$survey_id = $_POST["survey_id"];
	include_once 'success_result.php';
}

?>